<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盘点</title>
    <link rel="stylesheet" href="/css/elementui/index.css">
    <link rel="stylesheet" href="/css/exam/css/style.css">
    <link rel="stylesheet" href="/iconfont/iconfont.css">
    <script src="/css/exam/js/httpVueLoader.js"></script>
</head>
<body>
<div id="app">
  <!--导航切换-->
  <div class=".p-30">
  {{ csrf_field() }}
  <el-card>
  <el-form  :model="formInline" :rules="rules" ref="verification" label-width="100px">
  <!-- <el-card> -->
    <el-row>
      <p>出库清单添加</p>  
    </el-row>
    <el-row type="flex">
      <el-form-item label="出库类型" prop="name">
      <el-select v-model="formInline.name" disabled  style="width:200px">
      <el-option v-for="item in get_warehouse_type" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
		</el-select>
       </el-form-item>
      <el-form-item label="出库事由" prop="incident">
       <el-input v-model="formInline.incident"  style="width:200px"></el-input>
       </el-form-item>
      <el-form-item label="盘点单号" prop="check_number">
       <el-input v-model="formInline.check_number"  :disabled="true"  style="width:200px"></el-input>
       </el-form-item>
      <el-form-item label="申请人" prop="applicant">
       <el-input v-model="formInline.applicant"  style="width:200px"></el-input>
       </el-form-item>
    </el-row>
</el-form>
</el-card>
            <!-- 出库单添加 -->
            <div class="main" style="width: 100%; margin: 0 auto;">
            <h3 style="text-align: center">北宅街道应急物资盘点单</h3>
            <el-form ref="formData" :model="formData">
            <el-table  style="width: 100%" border :data="checkList">
                    <el-table-column  label="类&ensp;&ensp;别" width="" align='center' prop="goods.name">
                    </el-table-column>
                    <el-table-column    label="序&ensp;&ensp;号"   type='index' width="120" align='center'>
                    </el-table-column>
                    <el-table-column   label="物资名称"  width="" align='center' prop="materia.name">
                    </el-table-column>
                    <el-table-column    label="数&ensp;&ensp;量"  width="" align='center'  prop="check_num">
                    <!-- <template slot-scope="scope">
                       <el-input v-model='scope.row.sum'></el-input>
                    </template> -->
                    </el-table-column>
                    <el-table-column   label="单&ensp;&ensp;位"  width="" align='center' prop="warehouse_materials.unit">
                    </el-table-column>
                    <el-table-column   label="规&ensp;&ensp;格"  width="" align='center' prop="warehouse_materials.norms">
                    </el-table-column>
                    <el-table-column  label="所属单位"  width="" align='center' prop="checkcategory.name">
                    </el-table-column>
                    <el-table-column  label="单位名称" width="" align='center' prop="company.comName">
                    </el-table-column>
                    <el-table-column  label="具体位置"  width="" align='center' prop="company.address">
                    </el-table-column>
                    <el-table-column  label="备&ensp;&ensp;注" width="" align='center' prop="remarks">
                    </el-table-column>
         </el-table>
         </el-form>
         <div style="text-align: center">
            <el-row style="margin: 20px 0">
                <el-col>
                <el-button type="primary"  @click="submit">确&ensp;&ensp;定</el-button>   
                <el-button type="primary"  @click="cancellation">
                 取&ensp;&ensp;消
                </el-button>
                </el-col>
            </el-row>
             </div>
          
            </div>     
          </div>
  </div>
</div>
<script src="/css/exam/js/vue.js"></script>
<script src="/css/elementui/index.js"></script>
<script src="/css/exam/js/axios.min.js"></script>
<script>

const app = new Vue({
  el: '#app',
  data() {
    return { 
        id:'',
       
        dialogVisible:false,
        token:'',
        formInline:{
            name:'',
            incident:'盘点出库',
            applicant:'',
            check_number:'',
        },
        get_warehouse_type:[
          {
          value: '2',
          label: '盘点出库'
        }, 
        ],
        checkList:[],
        goodsdata:[], //分类名称
   
        formData:{
          sum:''
        },
        // 信息列表
        information:[],
        id:1,
        rules:{
            name:[{required: true, message: '请输入出库类型', trigger: 'blur'}],
            incident:[{required: true, message: '请输入出库事由', trigger: 'blur'},
            { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
           ],
            applicant:[{required: true, message: '请输入申请人', trigger: 'blur'},
            { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
           ],
           check_number:[{required: true, message: '请输入盘点单号', trigger: 'blur'},
            { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
           ],
         },
      
    }
  },

  
  created() {
    this.formInline.name = this.get_warehouse_type[0].value;
 
    // if (this.id) {
    //      let res =  localStorage.getItem(("list"))
    //      let a = JSON.parse(res)
    //      this.formInline.name = a.type
    //      this.formInline.incident = a.cause
    //      this.formInline.applicant = a.applicant
    // }
    this.getUrlKey()
    this.getEditTableList()
    this.token = '{{ csrf_token() }}'
    this.getQueryVariableId('type')
    this.current_user()
  },

  methods: {
      //获取当前浏览器地址url中的id
        getUrlKey() {
        var url = window.location.href ;             //获取当前url
        var dz_url = url.split('#')[0];              //获取#/之前的字符串
                                                        //获取?之后的参数字符串
	  		if (dz_url.split('?')[1] != undefined) {
				var cs = dz_url.split('?')[1];
				var cs_arr = cs.split('&');                  //参数字符串分割为数组
				var cs={};
				for(var i=0;i<cs_arr.length;i++){         //遍历数组，拿到json对象
				  cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
				}
				this.id = cs.id
			}			       
      },
     	  //拿到页面type
			getQueryVariableId(variable) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");
			for (var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
			return pair[1];
			}
			}
        },
      //回显
      async getEditTableList() {
      let odd_numbers = localStorage.getItem("odd_numbers")
      let res = await axios.get('/admin/check/materials_data',{
        params:{
            number:odd_numbers,
            type:this.getQueryVariableId('type')
         }
        
       
      })
        this.checkList = res.data.data
        console.log('res.data.data.check_number',res.data.data.check_number);

        this.checkList.forEach(element => {
            console.log('element',element.check_number);
            this.formInline.check_number = element.check_number
        });

    },
    //取消返  回上一页
    cancellation(){

     window.location.href = "/admin/warehouse/checkview" 

    },
     //添加
     async submit(){
       try {
        await this.$refs.verification.validate()   
      let outbound =[]
      this.checkList.forEach(element => {
       outbound.push({
       stock_id:element.warehouse_materials.id,
       number:element.check_num,
        })
       
      })
      let param={
        type:this.formInline.name,
        cause:this.formInline.incident,
        odd_numbers:this.formInline.check_number,
        applicant:this.formInline.applicant,
        _token:this.token,
        outbound:outbound

      }
      axios.post('/admin/warehouseOutbound/refer',param).then(res=>{
      console.log(res,306);
      if (res.data.code == 200) {  
           this.$message({
            message: '保存成功',
           type: 'success'
           });
          this.checkList = []
          window.location.href = "/admin/warehouse/checkview"
         } else {
         this.$message(res.data.message)
         }
    
      })
       } catch (error) {
        console.log('请求失败：' + error);
       }
 
    },

        //获取当前用户
       async current_user(){
         let res = await axios.get('/admin/user/getUser')
         this.formInline.applicant = res.data.data.name
        }

    },

  })

</script>
<style scoped>
  .el-table .el-table__cell:first-child{text-align: center;}
  .el-divider {
    margin:0;
  }
 



</style>
</body>
</html>


